from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-27 14:04:21.048083
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 27, Jun, 2022
Time: 14:04:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6116
Nobs: 700.000 HQIC: -49.9706
Log likelihood: 8719.55 FPE: 1.58431e-22
AIC: -50.1967 Det(Omega_mle): 1.39443e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298470 0.057758 5.168 0.000
L1.Burgenland 0.107443 0.037946 2.831 0.005
L1.Kärnten -0.109447 0.020085 -5.449 0.000
L1.Niederösterreich 0.212543 0.079257 2.682 0.007
L1.Oberösterreich 0.103331 0.077782 1.328 0.184
L1.Salzburg 0.257664 0.040585 6.349 0.000
L1.Steiermark 0.045707 0.052863 0.865 0.387
L1.Tirol 0.109158 0.042900 2.544 0.011
L1.Vorarlberg -0.059279 0.037216 -1.593 0.111
L1.Wien 0.039760 0.068711 0.579 0.563
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050039 0.121213 0.413 0.680
L1.Burgenland -0.033938 0.079634 -0.426 0.670
L1.Kärnten 0.041254 0.042151 0.979 0.328
L1.Niederösterreich -0.168202 0.166330 -1.011 0.312
L1.Oberösterreich 0.425050 0.163236 2.604 0.009
L1.Salzburg 0.289144 0.085173 3.395 0.001
L1.Steiermark 0.100831 0.110940 0.909 0.363
L1.Tirol 0.318900 0.090030 3.542 0.000
L1.Vorarlberg 0.028193 0.078103 0.361 0.718
L1.Wien -0.043888 0.144199 -0.304 0.761
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186071 0.029582 6.290 0.000
L1.Burgenland 0.090443 0.019435 4.654 0.000
L1.Kärnten -0.007959 0.010287 -0.774 0.439
L1.Niederösterreich 0.265690 0.040593 6.545 0.000
L1.Oberösterreich 0.136458 0.039838 3.425 0.001
L1.Salzburg 0.045968 0.020787 2.211 0.027
L1.Steiermark 0.020572 0.027075 0.760 0.447
L1.Tirol 0.091451 0.021972 4.162 0.000
L1.Vorarlberg 0.056446 0.019061 2.961 0.003
L1.Wien 0.116152 0.035192 3.301 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112208 0.030081 3.730 0.000
L1.Burgenland 0.045879 0.019762 2.322 0.020
L1.Kärnten -0.013752 0.010460 -1.315 0.189
L1.Niederösterreich 0.192469 0.041277 4.663 0.000
L1.Oberösterreich 0.302349 0.040509 7.464 0.000
L1.Salzburg 0.108342 0.021137 5.126 0.000
L1.Steiermark 0.104298 0.027531 3.788 0.000
L1.Tirol 0.103650 0.022342 4.639 0.000
L1.Vorarlberg 0.067736 0.019382 3.495 0.000
L1.Wien -0.023965 0.035785 -0.670 0.503
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133763 0.054931 2.435 0.015
L1.Burgenland -0.051012 0.036088 -1.414 0.157
L1.Kärnten -0.044380 0.019102 -2.323 0.020
L1.Niederösterreich 0.156114 0.075377 2.071 0.038
L1.Oberösterreich 0.140744 0.073974 1.903 0.057
L1.Salzburg 0.286222 0.038598 7.415 0.000
L1.Steiermark 0.047986 0.050275 0.954 0.340
L1.Tirol 0.166888 0.040799 4.090 0.000
L1.Vorarlberg 0.093137 0.035394 2.631 0.009
L1.Wien 0.072947 0.065347 1.116 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054730 0.043680 1.253 0.210
L1.Burgenland 0.037747 0.028697 1.315 0.188
L1.Kärnten 0.051083 0.015190 3.363 0.001
L1.Niederösterreich 0.218577 0.059939 3.647 0.000
L1.Oberösterreich 0.293382 0.058823 4.987 0.000
L1.Salzburg 0.047949 0.030693 1.562 0.118
L1.Steiermark 0.001726 0.039978 0.043 0.966
L1.Tirol 0.140878 0.032443 4.342 0.000
L1.Vorarlberg 0.073875 0.028145 2.625 0.009
L1.Wien 0.080940 0.051963 1.558 0.119
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175718 0.052246 3.363 0.001
L1.Burgenland -0.002240 0.034324 -0.065 0.948
L1.Kärnten -0.063091 0.018168 -3.473 0.001
L1.Niederösterreich -0.081332 0.071693 -1.134 0.257
L1.Oberösterreich 0.193906 0.070359 2.756 0.006
L1.Salzburg 0.056823 0.036712 1.548 0.122
L1.Steiermark 0.236707 0.047818 4.950 0.000
L1.Tirol 0.497804 0.038805 12.828 0.000
L1.Vorarlberg 0.044874 0.033664 1.333 0.183
L1.Wien -0.056657 0.062153 -0.912 0.362
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169789 0.059396 2.859 0.004
L1.Burgenland -0.011863 0.039022 -0.304 0.761
L1.Kärnten 0.063887 0.020655 3.093 0.002
L1.Niederösterreich 0.206157 0.081504 2.529 0.011
L1.Oberösterreich -0.077132 0.079988 -0.964 0.335
L1.Salzburg 0.213051 0.041736 5.105 0.000
L1.Steiermark 0.125957 0.054362 2.317 0.021
L1.Tirol 0.066802 0.044116 1.514 0.130
L1.Vorarlberg 0.119476 0.038272 3.122 0.002
L1.Wien 0.126255 0.070659 1.787 0.074
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.364005 0.034375 10.589 0.000
L1.Burgenland 0.007017 0.022583 0.311 0.756
L1.Kärnten -0.023511 0.011954 -1.967 0.049
L1.Niederösterreich 0.216446 0.047169 4.589 0.000
L1.Oberösterreich 0.204159 0.046292 4.410 0.000
L1.Salzburg 0.044355 0.024154 1.836 0.066
L1.Steiermark -0.015168 0.031461 -0.482 0.630
L1.Tirol 0.105651 0.025531 4.138 0.000
L1.Vorarlberg 0.069485 0.022149 3.137 0.002
L1.Wien 0.029833 0.040893 0.730 0.466
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037644 0.136926 0.193498 0.155138 0.114509 0.101621 0.057840 0.216610
Kärnten 0.037644 1.000000 -0.015038 0.134307 0.055869 0.095562 0.435760 -0.053168 0.093459
Niederösterreich 0.136926 -0.015038 1.000000 0.336357 0.141567 0.294647 0.092145 0.176959 0.311848
Oberösterreich 0.193498 0.134307 0.336357 1.000000 0.227406 0.325634 0.176111 0.163740 0.264710
Salzburg 0.155138 0.055869 0.141567 0.227406 1.000000 0.138160 0.116380 0.138894 0.130851
Steiermark 0.114509 0.095562 0.294647 0.325634 0.138160 1.000000 0.145563 0.129633 0.073421
Tirol 0.101621 0.435760 0.092145 0.176111 0.116380 0.145563 1.000000 0.113054 0.141775
Vorarlberg 0.057840 -0.053168 0.176959 0.163740 0.138894 0.129633 0.113054 1.000000 0.004720
Wien 0.216610 0.093459 0.311848 0.264710 0.130851 0.073421 0.141775 0.004720 1.000000